import json
import unittest
import requests
from api.login_api import LoginApi
from parameterized.parameterized import parameterized
import app


def list_info():
    data_json = []
    file_json = app.dir_url + '/data/login.json'
    with open(file_json, 'r', encoding='utf-8') as f:
        data_login = json.load(f)
        for da in data_login:
            login_data = da.get('login_data')
            status_code = da.get('status_code')
            success = da.get('success')
            code = da.get('code')
            message = da.get('message')
            data_json.append((login_data, status_code, success, code, message))
        return data_json


class TestLogin(unittest.TestCase):
    def setUp(self):
        self.login_api = LoginApi()

    @parameterized.expand(list_info())
    def test01_login(self, login_data, status_code, success, code, message):
        response = self.login_api.test01_login(login_data)
        print(response.json())
        self.assertEqual(status_code, response.status_code)
        self.assertEqual(success, response.json().get('success'))
        self.assertEqual(code, response.json().get('code'))
        self.assertIn(message, response.json().get('message'))
